package com.ruoyi.common.controller;

import java.util.List;

import com.ruoyi.common.entity.TodoEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.service.ITodoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * VIEWController
 * 
 * @author dustball
 * @date 2021-04-22
 */
@RestController
@RequestMapping("/oa/todo")
public class TodoController extends BaseController
{
    @Autowired
    private ITodoService todoService;

    /**
     * 查询VIEW列表
     */
    @PreAuthorize("@ss.hasPermi('oa:TodoEntity:list')")
    @GetMapping("/list")
    public TableDataInfo list(TodoEntity todo)
    {
        startPage();
        List<TodoEntity> list = todoService.selectTodoList(todo);
        return getDataTable(list);
    }

    /**
     * 导出VIEW列表
     */
    @PreAuthorize("@ss.hasPermi('oa:TodoEntity:export')")
    @Log(title = "VIEW", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TodoEntity todo)
    {
        List<TodoEntity> list = todoService.selectTodoList(todo);
        ExcelUtil<TodoEntity> util = new ExcelUtil<TodoEntity>(TodoEntity.class);
        return util.exportExcel(list, "TodoEntity");
    }

    /**
     * 获取VIEW详细信息
     */
    @PreAuthorize("@ss.hasPermi('oa:TodoEntity:query')")
    @GetMapping(value = "/{taskid}")
    public AjaxResult getInfo(@PathVariable("taskid") String taskid)
    {
        return AjaxResult.success(todoService.selectTodoById(taskid));
    }

    /**
     * 新增VIEW
     */
    @PreAuthorize("@ss.hasPermi('common:TodoEntity:add')")
    @Log(title = "VIEW", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TodoEntity todo)
    {
        return toAjax(todoService.insertTodo(todo));
    }

    /**
     * 修改VIEW
     */
    @PreAuthorize("@ss.hasPermi('common:TodoEntity:edit')")
    @Log(title = "VIEW", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TodoEntity todo)
    {
        return toAjax(todoService.updateTodo(todo));
    }

    /**
     * 删除VIEW
     */
    @PreAuthorize("@ss.hasPermi('common:TodoEntity:remove')")
    @Log(title = "VIEW", businessType = BusinessType.DELETE)
	@DeleteMapping("/{taskids}")
    public AjaxResult remove(@PathVariable String[] taskids)
    {
        return toAjax(todoService.deleteTodoByIds(taskids));
    }
}
